import { createApp, createVNode, render } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-plus'
import 'element-plus/dist/index.css'
import loadingBar from './components/loadingBar.vue'
const Vnode = createVNode(loadingBar)
render(Vnode, document.body)

const app = createApp(App)
app.use(router)
app.use(ElementUI)
const whileList = ['/']
router.beforeEach((to, form, next) => {
    document.title = to.meta.title
    Vnode.component?.exposed?.startLoading()
    if (whileList.includes(to.path) || localStorage.getItem('token')) {
        next()
    } else {
        next('/')
    }

})

router.afterEach((to, from) => {
    Vnode.component?.exposed?.endLoading()
})
app.mount('#app')
